<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'goods';

    public function scopeSearch($query, $params)
    {
        if(!empty($params['goods_name'])){
            $query->where('goods_name', 'like','%'.$params['goods_name'].'%');
        }
        if(!empty($params['manufacturer_id'])){
            $query->where('manufacturer_id', $params['manufacturer_id']);
        }
        if(!empty($params['cost_price'])){
            $query->where('cost_price', $params['cost_price']);
        }
        if(!empty($params['sales_price'])){
            $query->where('sales_price', $params['sales_price']);
        }
        return $query;
    }

    public function manufacturer(){
        return $this->belongsTo(Manufacturer::class);
    }
}
